home *** CD-ROM | disk | FTP | other *** search
/ Pulps on CDRom / Pulps on CDROM.iso / comm.z / Stack.js < prev    next >
Text File  |  1998-10-20  |  1KB  |  149 lines

  1. /* ==================================================================
  2.  
  3. FILE:   Stack.js
  4.  
  5. DESCR:  Stack object.
  6.  
  7. NOTES:  
  8.  
  9. ================================================================== */
  10.  
  11.  
  12.  
  13. /*
  14.  
  15. DESCR:   Stack class.
  16.  
  17. PARAMS:
  18.  
  19. RETURNS:
  20.  
  21. NOTES:
  22.  
  23. */
  24.  
  25. function stack()
  26.  
  27. {
  28.  
  29.    this.pointer = -1
  30.  
  31.    this.topItem
  32.  
  33.    this.aItems = new Array
  34.  
  35.  
  36.  
  37.    this.push    = push
  38.  
  39.    this.pop     = pop
  40.  
  41.    this.isEmpty = isEmpty
  42.  
  43.    this.clear   = clear
  44.  
  45. }
  46.  
  47.  
  48.  
  49.    /*
  50.  
  51.    DESCR:   
  52.  
  53.    PARAMS:  item  A variable of any type.
  54.  
  55.    RETURNS: 
  56.  
  57.    NOTES:   
  58.  
  59.    */
  60.  
  61.    function push( item )
  62.  
  63.    {
  64.  
  65.       this.topItem = item
  66.  
  67.       this.aItems[ ++this.pointer ] = item
  68.  
  69.    }
  70.  
  71.  
  72.  
  73.    /*
  74.  
  75.    DESCR:
  76.  
  77.    PARAMS:
  78.  
  79.    RETURNS: The item.
  80.  
  81.    NOTES:
  82.  
  83.    */
  84.  
  85.    function pop()
  86.  
  87.    {
  88.  
  89.       if ( this.isEmpty() ) return null
  90.  
  91.       this.topItem = this.aItems[ this.pointer - 1 ]
  92.  
  93.       return this.aItems[ this.pointer-- ]
  94.  
  95.    }
  96.  
  97.  
  98.  
  99.    /*
  100.  
  101.    DESCR:   Empties the stack.
  102.  
  103.    PARAMS:
  104.  
  105.    RETURNS:
  106.  
  107.    NOTES:
  108.  
  109.    */
  110.  
  111.    function clear()
  112.  
  113.    {
  114.  
  115.       this.pointer = -1
  116.  
  117.       this.topItem = null
  118.  
  119.    }
  120.  
  121.  
  122.  
  123.    /*
  124.  
  125.    DESCR:
  126.  
  127.    PARAMS:
  128.  
  129.    RETURNS: true if the stack contains no members; false otherwise.
  130.  
  131.    NOTES:
  132.  
  133.    */
  134.  
  135.    function isEmpty()
  136.  
  137.    {
  138.  
  139.       return ( this.pointer < 0 ? true : false )
  140.  
  141.    }
  142.  
  143.  
  144.  
  145. // End class definition: stack.
  146.  
  147.  
  148.  
  149.